package com.ruoyi.zhgd.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.zhgd.domain.TCustomReport;
import com.ruoyi.zhgd.mapper.TCustomReportMapper;
import com.ruoyi.zhgd.service.CustomReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description T00
 * @Author zky
 **/
@Service
public class CustomReportServiceImpl implements CustomReportService {

    @Autowired
    private TCustomReportMapper customReportMapper;

    /**
     * 新增
     *
     * @param customReport
     * @return
     */
    @Override
    public TCustomReport insertCustomReport(TCustomReport customReport) {
        customReport.setId(IdWorker.getId());
        customReport.setCreateBy(LoginHelper.getLoginUser().getUserId());

        customReport.setCreateTime(DateUtils.getNowDate());
        customReportMapper.insertCustomReport(customReport);
        return customReport;
    }

    /**
     * 发布/撤销
     *
     * @param customReport
     * @return
     */
    @Override
    public int updateCustomReport(TCustomReport customReport) {
        if (customReport.getId() != null) {
            customReport.setUpdateBy(LoginHelper.getLoginUser().getUserId());

            customReport.setUpdateTime(DateUtils.getNowDate());
            customReportMapper.updateCustomReport(customReport);
        } else {
            customReport.setId(IdWorker.getId());
            customReport.setCreateBy(LoginHelper.getLoginUser().getUserId());
            customReport.setCreateTime(DateUtils.getNowDate());
            customReportMapper.insertCustomReport(customReport);
        }
        return 1;
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteCustomReport(Long[] ids) {
        return customReportMapper.deleteByIds(ids);
    }

    /**
     * 模糊查询
     *
     * @param customReport
     * @return
     */
    @Override
    public Page<TCustomReport> selectCustomReportPageLike(PageQuery pageQuery, TCustomReport customReport) {
        Page<TCustomReport> data = customReportMapper.selectCustomReportPageLike(pageQuery.build(), customReport);
        return data;
    }

    /**
     * 根据ids查询详情
     *
     * @param ids
     * @return
     */
    @Override
    public List<TCustomReport> selectCustomReportByIds(Long[] ids, Integer status) {
        return customReportMapper.selectCustomReportByIds(ids, status);
    }
}
